﻿using Dapper;
using Estsh.Core.Base;
using Estsh.Core.Dapper;
using Estsh.Core.Model.Extend;
using Estsh.Core.Model.Extend.IFModels;
using Estsh.Core.Model.Extend.Models;
using Estsh.Core.Model.Result;
using Estsh.Core.Models;
using Estsh.Core.Repositories;
using Estsh.Core.Wms.IRepositories;
using System.Collections;
using System.Data;
using System.Text;

namespace Estsh.Core.Wms.Repositories
{
    /// <summary>
    /// ERP接口
    /// </summary>
    public class ERPInterfaceRepository : BaseRepository<BaseEntity>, IERPInterfaceRepository
    {
        public ERPInterfaceRepository(DapperDbContext _dapperDbContext) : base(_dapperDbContext)
        {

        }

        public sys_if_rec_config GetEquipReqIFConfig(string Code)
        {
            try
            {
                using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
                {
                    dbConn.Open();
                    string result = string.Empty;

                    string sql = "select * from sys_if_rec_config where enabled='1' and actionCode=@actionCode";
                    DynamicParameters parameters = new DynamicParameters();
                    parameters.Add("@actionCode", Code);

                    return dbConn.QueryFirstOrDefault<sys_if_rec_config>(sql.ToString(), parameters);
                }
            }
            catch (Exception ex)
            {

                throw;
            }
        }
        public WmsInterfaceResult GetInvokInterfaceData(ActionMessage actionMessage)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// 从SAP传递物料基本信息到WMS
        /// </summary>
        /// <param name="sapPt"></param>
        /// <returns></returns>
        public WmsInterfaceResult MaterialMasterMethod(string sid, List<SapPtInterface_Extend> sapPts)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapPts));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);


                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapPts.Count; i++)
                    {
                        SapPtInterface_Extend sapPt = sapPts[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_PT(MATNR,MAKTX,MTART,MTBEZ,MATKL,WGBEZ,MEINS ");
                        SqlStringBuilder.Append("           ,MAABC,BSTRF,WERKS,LVORM,SPART,ZZPPMATNR ");
                        SqlStringBuilder.Append("           ,SID,SYNFLG,ACTFLG,STAFLG ");
                        SqlStringBuilder.Append("           ,ISBATCH,CGTQQ,CGPC,WLDJ,REVUPPER,REVDOWMPER,CFUPPER,CFDOWMPER,INSTOCKUPPER,INSTOCKDOWMPER,ZRSTOCK ");
                        SqlStringBuilder.Append("           ,DOCK,OPTERATIONROLE,NETWEIGHT,PRICEMETHOD,MINPURCHASE,UNITPURCHASE,SAFETYSTOCK,EXEMPTION) ");
                        SqlStringBuilder.Append("     VALUES(@MATNR,@MAKTX,@MTART,@MTBEZ,@MATKL,@WGBEZ,@MEINS,@MAABC ");
                        SqlStringBuilder.Append("           ,@BSTRF,@WERKS,@LVORM,@SPART,@ZZPPMATNR,'" + sid + "' ");
                        SqlStringBuilder.Append("           ,'N','N','N' ");
                        SqlStringBuilder.Append("           ,@ISBATCH,@CGTQQ,@CGPC,@WLDJ,@REVUPPER,@REVDOWMPER,@CFUPPER,@CFDOWMPER,@INSTOCKUPPER,@INSTOCKDOWMPER,@ZRSTOCK ");
                        SqlStringBuilder.Append("           ,@DOCK,@OPTERATIONROLE,@NETWEIGHT,@PRICEMETHOD,@MINPURCHASE,@UNITPURCHASE,@SAFETYSTOCK,@EXEMPTION) ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@MATNR", sapPt.Matnr);
                        dynamic.Add("@MAKTX", sapPt.Maktx);
                        dynamic.Add("@MTART", sapPt.Mtart);
                        dynamic.Add("@MTBEZ", sapPt.Mtbez);
                        dynamic.Add("@MATKL", sapPt.Matkl);
                        dynamic.Add("@WGBEZ", sapPt.Wgbez);
                        dynamic.Add("@MEINS", sapPt.Meins);
                        dynamic.Add("@MAABC", sapPt.Maabc);
                        dynamic.Add("@BSTRF", sapPt.Bstrf);
                        dynamic.Add("@WERKS", sapPt.Werks);
                        dynamic.Add("@LVORM", sapPt.Lvorm);
                        dynamic.Add("@SPART", sapPt.Spart);
                        dynamic.Add("@ZZPPMATNR", sapPt.Zzppmatnr);
                        dynamic.Add("@ISBATCH", sapPt.IsBarch);
                        dynamic.Add("@CGTQQ", sapPt.Cgtqq);
                        dynamic.Add("@CGPC", sapPt.Cgpc);
                        dynamic.Add("@WLDJ", sapPt.Wldj);
                        dynamic.Add("@REVUPPER", sapPt.RevUpper);
                        dynamic.Add("@REVDOWMPER", sapPt.RevDownper);
                        dynamic.Add("@CFUPPER", sapPt.CfUpper);
                        dynamic.Add("@CFDOWMPER", sapPt.CfDownper);
                        dynamic.Add("@INSTOCKUPPER", sapPt.InStockUpper);
                        dynamic.Add("@INSTOCKDOWMPER", sapPt.InStockDownper);
                        dynamic.Add("@ZRSTOCK", sapPt.Zrstock);
                        dynamic.Add("@DOCK", sapPt.Dock);
                        dynamic.Add("@OPTERATIONROLE", sapPt.OpterationRole);
                        dynamic.Add("@NETWEIGHT", sapPt.Netweight);
                        dynamic.Add("@PRICEMETHOD", sapPt.PriceMethod);
                        dynamic.Add("@MINPURCHASE", sapPt.MinPurchase);
                        dynamic.Add("@UNITPURCHASE", sapPt.UnitPurchase);
                        dynamic.Add("@SAFETYSTOCK", sapPt.SafetyStock);
                        dynamic.Add("@EXEMPTION", sapPt.Exemption);
                        parameters.Add(dynamic);
                    }
                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.Message.ToString();
                }
                return interfaceResult;
            }
        }

        /// <summary>
        /// 从SAP传递供应商基本信息到WMS
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult SupplierMasterMethod(string sid, List<SapSuInterface> sapSus)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapSus));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapSus.Count; i++)
                    {
                        SapSuInterface sapSu = sapSus[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_SU(LIFNR,NAME1,STRAS,TELF1,PSTL2,NODEL ");
                        SqlStringBuilder.Append("           ,SYNFLG,ACTFLG,STAFLG,SID) ");
                        SqlStringBuilder.Append("     VALUES(@LIFNR,@NAME1,@STRAS,@TELF1,@PSTL2,@NODEL,'N' ");
                        SqlStringBuilder.Append("           ,'N','N','" + sid + "') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@LIFNR", sapSu.LIFNR);
                        dynamic.Add("@NAME1", sapSu.NAME1);
                        dynamic.Add("@STRAS", sapSu.STRAS);
                        dynamic.Add("@TELF1", sapSu.TELF1);
                        dynamic.Add("@PSTL2", sapSu.PSTL2);
                        dynamic.Add("@NODEL", sapSu.NODEL);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        /// <summary>
        /// 从SAP传递客户基本信息到WMS
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult CustomerMasterMethod(string sid, List<SapCuInterface> sapCus)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapCus));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapCus.Count; i++)
                    {
                        SapCuInterface sapCu = sapCus[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_CU(KUNNR,NAME1,STRAS,TELF1,PSTL2,NODEL,SID ");
                        SqlStringBuilder.Append("           ,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@KUNNR,@NAME1,@STRAS,@TELF1,@PSTL2,@NODEL,'" + sid + "' ");
                        SqlStringBuilder.Append("           ,'N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@KUNNR", sapCu.Kunnr);
                        dynamic.Add("@NAME1", sapCu.Name1);
                        dynamic.Add("@STRAS", sapCu.Stras);
                        dynamic.Add("@TELF1", sapCu.Telf1);
                        dynamic.Add("@PSTL2", sapCu.Pstl2);
                        dynamic.Add("@NODEL", sapCu.Nodel);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        /// <summary>
        /// 从SAP传递物料号与客户物料号对照信息到WMS
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult CustomerItemMasterMethod(string sid, List<SapPtcptInterface> sapPtcpts)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapPtcpts));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapPtcpts.Count; i++)
                    {
                        SapPtcptInterface sapPtcpt = sapPtcpts[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_PTCPT(KUNNR,MATNR,KDMAT,ZZ_TYPE,SID,SYNFLG ");
                        SqlStringBuilder.Append("           ,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@KUNNR,@MATNR,@KDMAT,@ZZTYPE,'" + sid + "','N' ");
                        SqlStringBuilder.Append("           ,'N','N') ");

                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@KUNNR", sapPtcpt.Kunnr);
                        dynamic.Add("@MATNR", sapPtcpt.Matnr);
                        dynamic.Add("@KDMAT", sapPtcpt.Kdmat);
                        dynamic.Add("@ZZTYPE", sapPtcpt.ZzType);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        /// <summary>
        /// MBOM同步到MES系统
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult BomMasterMethod(string sid, List<SapBomInterface_Extend> sapBoms)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapBoms));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapBoms.Count; i++)
                    {
                        SapBomInterface_Extend sapBom = sapBoms[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_BOM(WERKS,MATNR,BMENG,BMEIN,IDNRK,MENGE,MEINS,DATUV,DATUS ");
                        SqlStringBuilder.Append("           ,LKENZ,AENNR,SID,SYNFLG,ACTFLG,STAFLG ");
                        SqlStringBuilder.Append("           ,DELIVERYMODEL,WHETHERSKIP,ATTRITIONRATE,DEFAULTWAREHOUSE,PROCEDURECODE,OUTIDENTITY)");
                        SqlStringBuilder.Append("     VALUES(@WERKS,@MATNR,@BMENG,@BMEIN,@IDNRK,@MENGE,@MEINS,@DATUV,@DATUS,@LKENZ ");
                        SqlStringBuilder.Append("           ,@AENNR,'" + sid + "','N','N','N' ");
                        SqlStringBuilder.Append("           ,@DELIVERYMODEL,@WHETHERSKIP,@ATTRITIONRATE,@DEFAULTWAREHOUSE,@PROCEDURECODE,@OUTIDENTITY)");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@WERKS", sapBom.Werks);
                        dynamic.Add("@MATNR", sapBom.Matnr);
                        dynamic.Add("@BMENG", sapBom.Bmeng);
                        dynamic.Add("@BMEIN", sapBom.Bmein);
                        dynamic.Add("@IDNRK", sapBom.Idnrk);
                        dynamic.Add("@MENGE", sapBom.Menge);
                        dynamic.Add("@MEINS", sapBom.Meins);
                        dynamic.Add("@DATUV", sapBom.Datuv);
                        dynamic.Add("@DATUS", sapBom.Datus);
                        dynamic.Add("@LKENZ", sapBom.Lkenz);
                        dynamic.Add("@AENNR", sapBom.Aennr);
                        dynamic.Add("@DELIVERYMODEL", sapBom.Deliverymodel);
                        dynamic.Add("@WHETHERSKIP", sapBom.Whetherskip);
                        dynamic.Add("@ATTRITIONRATE", sapBom.Attritionrate);
                        dynamic.Add("@DEFAULTWAREHOUSE", sapBom.Defaultwarehouse);
                        dynamic.Add("@PROCEDURECODE", sapBom.Procedurecode);
                        dynamic.Add("@OUTIDENTITY", sapBom.Outidentity);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        /// <summary>
        /// SAP系统把ASN传递到WMS用于采购收货
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult ASNDataMethod(string sid, List<SapAsnInterface> sapAsns)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapAsns));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapAsns.Count; i++)
                    {
                        SapAsnInterface sapAsn = sapAsns[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_ASN(ZASNNO,LIFNR,ZRNUM,MATNR,ZCN_NUM,UNIT,PSTYP,ZDATE,ZCJSJ ");
                        SqlStringBuilder.Append("           ,WERKS,LGORT,ZSTAS,ZTXM,SID,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@ZASNNO,@LIFNR,@ZRNUM,@MATNR,@ZCNNUM,@UNIT,@PSTYP,@ZDATE,@ZCJSJ,@WERKS ");
                        SqlStringBuilder.Append("           ,@LGORT,@ZSTAS,@ZTXM,'" + sid + "','N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@ZASNNO", sapAsn.Zasnno);
                        dynamic.Add("@LIFNR", sapAsn.Lifnr);
                        dynamic.Add("@ZRNUM", sapAsn.Zrnum);
                        dynamic.Add("@MATNR", sapAsn.Matnr);
                        dynamic.Add("@ZCNNUM", sapAsn.ZCN_NUM);
                        dynamic.Add("@UNIT", sapAsn.Unit);
                        dynamic.Add("@PSTYP", sapAsn.Pstyp);
                        dynamic.Add("@ZDATE", sapAsn.Zdate);
                        dynamic.Add("@ZCJSJ", sapAsn.Zcjsj);
                        dynamic.Add("@WERKS", sapAsn.Werks);
                        dynamic.Add("@LGORT", sapAsn.Lgort);
                        dynamic.Add("@ZSTAS", sapAsn.Zstas);
                        dynamic.Add("@ZTXM", sapAsn.Ztxm);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        /// <summary>
        /// SAP系统把PO传递到WMS用于采购收货
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult PODataMethod(string sid, List<SapDspoInterface_Extend> sapDspos)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapDspos));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapDspos.Count; i++)
                    {
                        SapDspoInterface_Extend sapDspo = sapDspos[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_DSPO(EBELN,EVRTP,LIFNR,MATNR,ZDEV_NUM,UNIT,PSTYP,ZDATE,ZCJSJ,WERKS,ITEMTYPE,PURCHASENO ");
                        SqlStringBuilder.Append("           ,LGORT,ZSTAS,BSTYP,BSTRF,SID,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@EBELN,@EVRTP,@LIFNR,@MATNR,@ZDEVNUM,@UNIT,@PSTYP,@ZDATE,@ZCJSJ,@WERKS,@ITEMTYPE,@PURCHASENO,@LGORT,@ZSTAS ");
                        SqlStringBuilder.Append("           ,@BSTYP,@BSTRF,'" + sid + "','N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@EBELN", sapDspo.Ebeln);
                        dynamic.Add("@ITEMTYPE", sapDspo.ItemType);
                        dynamic.Add("@PURCHASENO", sapDspo.Purchaseno);
                        dynamic.Add("@EVRTP", sapDspo.Evrtp);
                        dynamic.Add("@LIFNR", sapDspo.Lifnr);
                        dynamic.Add("@MATNR", sapDspo.Matnr);
                        dynamic.Add("@ZDEVNUM", sapDspo.Zdev_Num);
                        dynamic.Add("@UNIT", sapDspo.Unit);
                        dynamic.Add("@PSTYP", sapDspo.Pstyp);
                        dynamic.Add("@ZDATE", sapDspo.Zdate);
                        dynamic.Add("@ZCJSJ", sapDspo.Zcjsj);
                        dynamic.Add("@WERKS", sapDspo.Werks);
                        dynamic.Add("@LGORT", sapDspo.Lgort);
                        dynamic.Add("@ZSTAS", sapDspo.Zstas);
                        dynamic.Add("@BSTYP", sapDspo.Bstyp);
                        dynamic.Add("@BSTRF", sapDspo.Bstrf);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        /// <summary>
        /// SAP系统将一定期间内待发运交货单信息发布到WMS用于后续捡配发货
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult SalesAndDeliveryPlanMethod(string sid, List<SapDnInterface> sapDns)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapDns));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapDns.Count; i++)
                    {
                        SapDnInterface sapDn = sapDns[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_DN(VBELN,POSNR,WERKS,LGORT,LFDAT,KUNNR,MATNR,KDMAT,LFIMG,MEINS ");
                        SqlStringBuilder.Append("           ,SID,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@VBELN,@POSNR,@WERKS,@LGORT,@LFDAT,@KUNNR,@MATNR,@KDMAT,@LFIMG ");
                        SqlStringBuilder.Append("           ,@MEINS,'" + sid + "','N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@VBELN", sapDn.Vbeln);
                        dynamic.Add("@POSNR", sapDn.Posnr);
                        dynamic.Add("@WERKS", sapDn.Werks);
                        dynamic.Add("@LGORT", sapDn.Lgort);
                        dynamic.Add("@LFDAT", sapDn.Lfdat);
                        dynamic.Add("@KUNNR", sapDn.Kunnr);
                        dynamic.Add("@MATNR", sapDn.Matnr);
                        dynamic.Add("@KDMAT", sapDn.Kdmat);
                        dynamic.Add("@LFIMG", sapDn.Lfimg);
                        dynamic.Add("@MEINS", sapDn.Meins);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        /// <summary>
        /// SAP把物料的零星出(入）指令传到WMS
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult SporadicEntryAndExitMethod(string sid, List<SapMiscoInterface> sapMiscos)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapMiscos));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapMiscos.Count; i++)
                    {
                        SapMiscoInterface sapMisco = sapMiscos[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_MISCO(ZINSTNO,ZEILE,WERKS,LGORT,MATNR,ERFMG,ERFME,SOBKZ ");
                        SqlStringBuilder.Append("           ,HTEXT,ZZLZT,ZACTION,SID,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@ZINSTNO,@ZEILE,@WERKS,@LGORT,@MATNR,@ERFMG,@ERFME,@SOBKZ,@HTEXT ");
                        SqlStringBuilder.Append("           ,@ZZLZT,@ZACTION,'" + sid + "','N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@ZINSTNO", sapMisco.Zinstno);
                        dynamic.Add("@ZEILE", sapMisco.Zeile);
                        dynamic.Add("@WERKS", sapMisco.Werks);
                        dynamic.Add("@LGORT", sapMisco.Lgort);
                        dynamic.Add("@MATNR", sapMisco.Matnr);
                        dynamic.Add("@ERFMG", sapMisco.Erfmg);
                        dynamic.Add("@ERFME", sapMisco.Erfme);
                        dynamic.Add("@SOBKZ", sapMisco.Sobkz);
                        dynamic.Add("@HTEXT", sapMisco.Htext);
                        dynamic.Add("@ZZLZT", sapMisco.Zzlzt);
                        dynamic.Add("@ZACTION", sapMisco.Zaction);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }
        /// <summary>
        /// SAP把物料的零星出(入）指令传到WMS
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult SporadicEntryAndExitExtendMethod(string sid, List<SapMiscoInterface_Extend> sapMiscos)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapMiscos));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapMiscos.Count; i++)
                    {
                        SapMiscoInterface_Extend sapMisco = sapMiscos[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_MISCO(ZINSTNO,ZEILE,WERKS,LGORT,MATNR,ERFMG,ERFME,SOBKZ ");
                        SqlStringBuilder.Append("           ,HTEXT,ZZLZT,ZACTION,DEPARTMENT,REFORDERNO,SID,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@ZINSTNO,@ZEILE,@WERKS,@LGORT,@MATNR,@ERFMG,@ERFME,@SOBKZ,@HTEXT ");
                        SqlStringBuilder.Append("           ,@ZZLZT,@ZACTION,@DEPARTMENT,@REFORDERNO,'" + sid + "','N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@ZINSTNO", sapMisco.Zinstno);
                        dynamic.Add("@ZEILE", sapMisco.Zeile);
                        dynamic.Add("@WERKS", sapMisco.Werks);
                        dynamic.Add("@LGORT", sapMisco.Lgort);
                        dynamic.Add("@MATNR", sapMisco.Matnr);
                        dynamic.Add("@ERFMG", sapMisco.Erfmg);
                        dynamic.Add("@ERFME", sapMisco.Erfme);
                        dynamic.Add("@SOBKZ", sapMisco.Sobkz);
                        dynamic.Add("@HTEXT", sapMisco.Htext);
                        dynamic.Add("@ZZLZT", sapMisco.Zzlzt);
                        dynamic.Add("@ZACTION", sapMisco.Zaction);
                        dynamic.Add("@DEPARTMENT", sapMisco.DepartMent);
                        dynamic.Add("@REFORDERNO", sapMisco.RefOrderNo);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }
        /// <summary>
        /// 盘点开始时，SAP冻结库存，并把盘点表传到WMS
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult InventoryListMethod(string sid, List<SapCycoInterface> sapCycos)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapCycos));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapCycos.Count; i++)
                    {
                        SapCycoInterface sapCyco = sapCycos[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_CYCO(IBLNR,ZEILI,MATNR,MEINS,WERKS,LGORT,ZSTAT,SOBKZ ");
                        SqlStringBuilder.Append("           ,GJAHR,SID,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@IBLNR,@ZEILI,@MATNR,@MEINS,@WERKS,@LGORT,@ZSTAT,@SOBKZ,@GJAHR ");
                        SqlStringBuilder.Append("           ,'" + sid + "','N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@IBLNR", sapCyco.Iblnr);
                        dynamic.Add("@ZEILI", sapCyco.Zeili);
                        dynamic.Add("@MATNR", sapCyco.Matnr);
                        dynamic.Add("@MEINS", sapCyco.Meins);
                        dynamic.Add("@WERKS", sapCyco.Werks);
                        dynamic.Add("@LGORT", sapCyco.Lgort);
                        dynamic.Add("@ZSTAT", sapCyco.Zstat);
                        dynamic.Add("@SOBKZ", sapCyco.Sobkz);
                        dynamic.Add("@GJAHR", sapCyco.Gjahr);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        /// <summary>
        /// SAP把盘点差异转移到差异库的结果传到WMS，使得WMS可以根据盘点结果调整库存
        /// </summary>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public WmsInterfaceResult InventoryDifferenceAdjustmentMethod(string sid, List<SapDifoInterface> sapDifos)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapDifos));
                    IQdynamic.Add("@ACTFLG", 'N');
                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapDifos.Count; i++)
                    {
                        SapDifoInterface sapDifo = sapDifos[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_DIFO(WERKS,IBLNR,ZEILI,ZTZBS,GJAHR,SID ");
                        SqlStringBuilder.Append("           ,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@WERKS,@IBLNR,@ZEILI,@ZTZBS,@GJAHR,'" + sid + "','N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@WERKS", sapDifo.Werks);
                        dynamic.Add("@IBLNR", sapDifo.Iblnr);
                        dynamic.Add("@ZEILI", sapDifo.Zeili);
                        dynamic.Add("@ZTZBS", sapDifo.Ztzbs);
                        dynamic.Add("@GJAHR", sapDifo.Gjahr);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult WorkCenterMethod(string sid, List<SapWorkcenter> sapWorkcenters)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapWorkcenters));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapWorkcenters.Count; i++)
                    {
                        SapWorkcenter sapWorkc = sapWorkcenters[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_WORKCENTER(ENCODE,WORKCENTERNAME,FIXEDCOST,WORKSHOP,PRODUCTIONLINE ");
                        SqlStringBuilder.Append("           ,SYNFLG,ACTFLG,STAFLG,SID) ");
                        SqlStringBuilder.Append("     VALUES(@ENCODE,@WORKCENTERNAME,@FIXEDCOST,@WORKSHOP,@PRODUCTIONLINE,'N' ");
                        SqlStringBuilder.Append("           ,'N','N','" + sid + "') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@ENCODE", sapWorkc.Encode);
                        dynamic.Add("@WORKCENTERNAME", sapWorkc.Workcentername);
                        dynamic.Add("@FIXEDCOST", sapWorkc.Fixedcost);
                        dynamic.Add("@WORKSHOP", sapWorkc.Workshop);
                        dynamic.Add("@PRODUCTIONLINE", sapWorkc.Productionline);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult ProcessInfoMethod(string sid,List<SapProcessinfo> processinfos)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(processinfos));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < processinfos.Count; i++)
                    {
                        SapProcessinfo processinfo = processinfos[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_PROCESSINFO(PROCEDURECODE,PROCESSNAME,PROCESSTYPE ");
                        SqlStringBuilder.Append("           ,SYNFLG,ACTFLG,STAFLG,SID) ");
                        SqlStringBuilder.Append("     VALUES(@PROCEDURECODE,@PROCESSNAME,@PROCESSTYPE,'N' ");
                        SqlStringBuilder.Append("           ,'N','N','" + sid + "') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@PROCEDURECODE", processinfo.Procedurecode);
                        dynamic.Add("@PROCESSNAME", processinfo.Processname);
                        dynamic.Add("@PROCESSTYPE", processinfo.Processtype);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult StockInfoMethod(string sid, List<SapStockinfo> sapStockinfos)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapStockinfos));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapStockinfos.Count; i++)
                    {
                        SapStockinfo stockinfo = sapStockinfos[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_STOCKINFO(MATERIALCODE,MATERIALNAME,ITEMNO,STOCKQTY ");
                        SqlStringBuilder.Append("           ,SYNFLG,ACTFLG,STAFLG,SID) ");
                        SqlStringBuilder.Append("     VALUES(@MATERIALCODE,@MATERIALNAME,@ITEMNO,@STOCKQTY,'N' ");
                        SqlStringBuilder.Append("           ,'N','N','" + sid + "') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@MATERIALCODE", stockinfo.Materialcode);
                        dynamic.Add("@MATERIALNAME", stockinfo.Materialname);
                        dynamic.Add("@ITEMNO", stockinfo.Itemno);
                        dynamic.Add("@STOCKQTY", stockinfo.Stockqty);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult WmsLogisticsMethod(string sid, List<WmsLogistics> wmsLogistics)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(wmsLogistics));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < wmsLogistics.Count; i++)
                    {
                        WmsLogistics logistics  = wmsLogistics[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.WMS_LOGISTICS(LOGISTICSNAME,LOGISTICSCODE,AREA,STARTINGPRICE ");
                        SqlStringBuilder.Append("           ,FIRSTVALUE,PRICINGRULE,UNIT,ENABLED");
                        SqlStringBuilder.Append("           ,SYNFLG,ACTFLG,STAFLG,SID) ");
                        SqlStringBuilder.Append("     VALUES(@LOGISTICSNAME,@LOGISTICSCODE,@AREA,@STARTINGPRICE ");
                        SqlStringBuilder.Append("           ,@FIRSTVALUE,@PRICINGRULE,@UNIT,@ENABLED");
                        SqlStringBuilder.Append("           ,'N','N','N','" + sid + "') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@LOGISTICSNAME", logistics.Logisticsname);
                        dynamic.Add("@LOGISTICSCODE", logistics.Logisticscode);
                        dynamic.Add("@AREA", logistics.Area);
                        dynamic.Add("@STARTINGPRICE", logistics.Startingprice);
                        dynamic.Add("@FIRSTVALUE", logistics.Firstvalue);
                        dynamic.Add("@PRICINGRULE", logistics.Pricingrule);
                        dynamic.Add("@UNIT", logistics.Unit);
                        dynamic.Add("@ENABLED", logistics.Enabled);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult PersonMethod(string sid, List<WmsPerson> people)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(people));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < people.Count; i++)
                    {
                        WmsPerson person = people[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.WMS_PERSON(SERIALNO,NAME,JOBNO,DEPARTMENT ");
                        SqlStringBuilder.Append("           ,SEX,TEL,CLASSTYPE,ENABLED");
                        SqlStringBuilder.Append("           ,SYNFLG,ACTFLG,STAFLG,SID) ");
                        SqlStringBuilder.Append("     VALUES(@SERIALNO,@NAME,@JOBNO,@DEPARTMENT ");
                        SqlStringBuilder.Append("           ,@SEX,@TEL,@CLASSTYPE,@ENABLED");
                        SqlStringBuilder.Append("           ,'N','N','N','" + sid + "') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@SERIALNO", person.Serialno);
                        dynamic.Add("@NAME", person.Name);
                        dynamic.Add("@JOBNO", person.Jobno);
                        dynamic.Add("@DEPARTMENT", person.Department);
                        dynamic.Add("@SEX", person.Sex);
                        dynamic.Add("@TEL", person.Tel);
                        dynamic.Add("@CLASSTYPE", person.Classtype);
                        dynamic.Add("@ENABLED", person.Enabled);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult WareHouseMethod(string sid, List<WmsWh> wmsWhs)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(wmsWhs));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < wmsWhs.Count; i++)
                    {
                        WmsWh warehouse = wmsWhs[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.WMS_WH(WHCODE,WHNAME,ENABLED ");
                        SqlStringBuilder.Append("           ,SYNFLG,ACTFLG,STAFLG,SID) ");
                        SqlStringBuilder.Append("     VALUES(@WHCODE,@WHNAME,@ENABLED ");
                        SqlStringBuilder.Append("           ,'N','N','N','" + sid + "') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@WHCODE", warehouse.Whcode);
                        dynamic.Add("@WHNAME", warehouse.Whname);
                        dynamic.Add("@ENABLED", warehouse.Enabled);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }
        /// <summary>
        /// 物料分组
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="sapwlGroup"></param>
        /// <returns></returns>
        public WmsInterfaceResult MaterialGroupMethod(string sid, List<SapwlGroup> sapwlGroup)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapwlGroup));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapwlGroup.Count; i++)
                    {
                        StringBuilder SqlStringBuilder = new StringBuilder(1024);
                        SapwlGroup sapInfo = sapwlGroup[i];
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_WLGROUP (FMATERIALGROUP ,FGROUP1 ,FGROUP2 ,FGROUP3 ,FGROUP4 , FGROUP5,ENABLED,SYNFLG,ACTFLG,STAFLG,SID)");
                        SqlStringBuilder.Append("  VALUES (@FMATERIALGROUP ,@FGROUP1 ,@FGROUP2 ,@FGROUP3 ,@FGROUP4 , @FGROUP5,@ENABLED ");
                        SqlStringBuilder.Append("   ,'N','N','N',@SID)");

                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@FMATERIALGROUP", sapInfo.Fmaterialgroup);
                        dynamic.Add("@FGROUP1", sapInfo.FGGoup1);
                        dynamic.Add("@FGROUP2", sapInfo.FGGoup2);
                        dynamic.Add("@FGROUP3", sapInfo.FGGoup3);
                        dynamic.Add("@FGROUP4", sapInfo.FGGoup4);
                        dynamic.Add("@FGROUP5", sapInfo.FGGoup5);
                        dynamic.Add("@ENABLED", sapInfo.ENABLED);
                        dynamic.Add("@SID", sid);
                        parameters.Add(dynamic);
                    }
                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.Message.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult ZoneMethod(string sid, List<WmsZone> wmsZones)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(wmsZones));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < wmsZones.Count; i++)
                    {
                        WmsZone zone = wmsZones[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.WMS_ZONE(ZONENAME,ZONEDESC,WAREHOUSENAME ");
                        SqlStringBuilder.Append("           ,ERPWAREHOUSE,ENABLED");
                        SqlStringBuilder.Append("           ,SYNFLG,ACTFLG,STAFLG,SID) ");
                        SqlStringBuilder.Append("     VALUES(@ZONENAME,@ZONEDESC,@WAREHOUSENAME ");
                        SqlStringBuilder.Append("           ,@ERPWAREHOUSE,@ENABLED");
                        SqlStringBuilder.Append("           ,'N','N','N','" + sid + "') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@ZONENAME", zone.Zonename);
                        dynamic.Add("@ZONEDESC", zone.Zonedesc);
                        dynamic.Add("@WAREHOUSENAME", zone.Warehousename);
                        dynamic.Add("@ERPWAREHOUSE", zone.Erpwarehouse);
                        dynamic.Add("@ENABLED", zone.Enabled);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult QCMethod(string sid, List<WmsToqce> wmsToqcs)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(wmsToqcs));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < wmsToqcs.Count; i++)
                    {
                        
                        WmsToqce toqc = wmsToqcs[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.WMS_TOQCE(BSTYP,EVRTN,ISQCCOM,LIFNR,LOTON ");
                        SqlStringBuilder.Append("           ,ETENR,PARTNONUM,ZDEV,NZDEV,PARTNO");
                        SqlStringBuilder.Append("           ,SYNFLG,ACTFLG,STAFLG,SID) ");
                        SqlStringBuilder.Append("     VALUES(@BSTYP,@EVRTN,@ISQCCOM,@LIFNR,@LOTON ");
                        SqlStringBuilder.Append("           ,@ETENR,@QCNUM,@ZDEV,@NZDEV,@PART_NO");
                        SqlStringBuilder.Append("           ,'N','N','N','" + sid + "') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        StringBuilder builder = new StringBuilder(1024);
                        builder.Append($"SELECT * FROM dbo.WMS_TOQC where ETENR='{toqc.Etenr}'");
                        List<WmsToqc> toqcs= dbConn.Query<WmsToqc>(builder.ToString()).ToList();

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@BSTYP", toqc.Bstyp);
                        dynamic.Add("@EVRTN", toqc.Evrtn);
                        dynamic.Add("@ISQCCOM", toqc.IsQcCom);
                        dynamic.Add("@ETENR", toqc.Etenr);
                        dynamic.Add("@QCNUM", toqc.PartNoNum);
                        dynamic.Add("@ZDEV", toqc.Zdev);
                        dynamic.Add("@NZDEV", toqc.NZdev);
                        dynamic.Add("@PART_NO", toqc.PartNo);
                        dynamic.Add("@LIFNR",toqcs.Count>0?toqcs.FirstOrDefault().Lifnr:" ");
                        dynamic.Add("@LOTON", toqcs.Count > 0 ? toqcs.FirstOrDefault().Loton : " ");

                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }



                    
        /// <summary>
        /// 获取工艺路线
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="sapwlGroup"></param>
        /// <returns></returns>
        public WmsInterfaceResult RouttingMethod(string sid, List<SapRouting> sapwlGroup)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapwlGroup));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);


                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapwlGroup.Count; i++)
                    {
                        StringBuilder SqlStringBuilder = new StringBuilder(1024);
                        SapRouting sapInfo = sapwlGroup[i];
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_ROUTE ( WLCODE , ROUTECODE ,STATION ,STATIONNUM ,GZTYPE ,HOURTIME , GXPEOPLE , ENABLED ,SID ,SYNFLG,ACTFLG,STAFLG)");
                        SqlStringBuilder.Append("  VALUES  (@WLCODE , @ROUTECODE ,@STATION ,@STATIONNUM,@GZTYPE,@HOURTIME, @GXPEOPLE , @ENABLED ,@SID  ");
                        SqlStringBuilder.Append("   ,'N','N','N')");

                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@WLCODE", sapInfo.wlcode);
                        dynamic.Add("@ROUTECODE", sapInfo.routecode);
                        dynamic.Add("@STATION", sapInfo.station);
                        dynamic.Add("@STATIONNUM", sapInfo.stationnum);
                        dynamic.Add("@HOURTIME", sapInfo.hourtime);
                        dynamic.Add("@GZTYPE", sapInfo.gztype);
                        dynamic.Add("@GXPEOPLE", sapInfo.gxpeople);
                        dynamic.Add("@ENABLED", sapInfo.ENABLED);
                        dynamic.Add("@SID", sid);
                        parameters.Add(dynamic);
                    }
                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.Message.ToString();
                }
                return interfaceResult;
            }
        }
        /// <summary>
        /// 工种信息
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="sapItemListParam"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WmsInterfaceResult WorkItemMethod(string sid, List<SapWorkItem> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);


                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        StringBuilder SqlStringBuilder = new StringBuilder(1024);
                        SapWorkItem sapInfo = sapItemListParam[i];
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_WORKITEM ( ITEMCODE ,ITEMNAME ,HOURSALARY ,STATIONCHANGE ,ENABLED ,SID ,SYNFLG,ACTFLG,STAFLG )");
                        SqlStringBuilder.Append("  VALUES  ( @ITEMCODE ,@ITEMNAME ,@HOURSALARY ,@STATIONCHANGE ,@ENABLED ,@SID   ");
                        SqlStringBuilder.Append("   ,'N','N','N')");

                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@ITEMCODE", sapInfo.ItemCode);
                        dynamic.Add("@ITEMNAME", sapInfo.ItemName);
                        dynamic.Add("@HOURSALARY", sapInfo.HourSalary);
                        dynamic.Add("@STATIONCHANGE", sapInfo.StationChange);
                        dynamic.Add("@ENABLED", sapInfo.ENABLED);
                        dynamic.Add("@SID", sid);
                        parameters.Add(dynamic);
                    }
                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.Message.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult SalesHistoryMethod(string sid, List<SapSalesHistory> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);


                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        StringBuilder SqlStringBuilder = new StringBuilder(1024);
                        SapSalesHistory sapInfo = sapItemListParam[i];
                        SqlStringBuilder.Append("INSERT INTO dbo.Sap_SalesHistory (PAETCODE ,AVE3SALESNUM ,AVE6SALESNUM ,CATEGORY ,DATE,ENABLED ,SID,SYNFLG,ACTFLG,STAFLG)");
                        SqlStringBuilder.Append("  VALUES (@PAETCODE ,@AVE3SALESNUM ,@AVE6SALESNUM ,@CATEGORY ,@DATE ,@ENABLED ,@SID ");
                        SqlStringBuilder.Append("   ,'N','N','N')");

                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@PAETCODE", sapInfo.PartCode);
                        dynamic.Add("@AVE3SALESNUM", sapInfo.Ave3SalesNum);
                        dynamic.Add("@AVE6SALESNUM", sapInfo.Ave6SalesNum);
                        dynamic.Add("@CATEGORY", sapInfo.Category);
                        dynamic.Add("@DATE", sapInfo.Date);
                        dynamic.Add("@ENABLED", sapInfo.ENABLED);
                        dynamic.Add("@SID", sid);
                        parameters.Add(dynamic);
                    }
                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.Message.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult CalculateOrderMethod(string sid, List<SapCalculate> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);


                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        StringBuilder SqlStringBuilder = new StringBuilder(1024);
                        SapCalculate sapInfo = sapItemListParam[i];
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_Calculate ( ORDERNO , PARTCODE , QTY , ENABLED ,SID ,SYNFLG,ACTFLG,STAFLG)");
                        SqlStringBuilder.Append("  VALUES  ( @ORDERNO , @PARTCODE , @QTY , @ENABLED ,@SID  ");
                        SqlStringBuilder.Append("   ,'N','N','N')");

                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@PARTCODE", sapInfo.PartCode);
                        dynamic.Add("@ORDERNO", sapInfo.OrderNo);
                        dynamic.Add("@QTY", sapInfo.Qty);
                        dynamic.Add("@ENABLED", sapInfo.ENABLED);
                        dynamic.Add("@SID", sid);
                        parameters.Add(dynamic);
                    }
                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.Message.ToString();
                }
                return interfaceResult;
            }
        }
        /// <summary>
        /// 月度评审结果
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="sapItemListParam"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public WmsInterfaceResult MonthReviewResultMethod(string sid, List<SapMonthReviewResult> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);


                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        StringBuilder SqlStringBuilder = new StringBuilder(1024);
                        SapMonthReviewResult sapInfo = sapItemListParam[i];
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_Month_ReviewResult ( PARTCODE ,PDLINENAME ,PDLINE ,CATEGORY ,SOURCE ,QTY ,CRAFTHOUR ,CRAFTPAY ,REALITYHOUR ,REALITYPAY ,");
                        SqlStringBuilder.Append(" PAYDIFFER ,MOUTHASM ,MOUTHPRODUCT ,REQUEST3MOHTH,SALEREQUESTCO ,SALENETDEMAND ,FIRSTSUMPRODUCT ,MAXPRODUCTQTY ,LASTPRODUCTPLAN ,");
                        SqlStringBuilder.Append(" LASTPRODUCTHOUR ,LASTPRODUCTLOAD ,LASTPRODUCTVALUE ,LASTPRODUCTPEOPLE ,ISEXECT ,REALTIMESTOKC ,AGVOUTPRICE ,SUMPEOPLEHOUR,ENABLED,SID ,SYNFLG,ACTFLG,STAFLG)");
                        SqlStringBuilder.Append("  VALUES  ( @PARTCODE ,@PDLINENAME ,@PDLINE ,@CATEGORY ,@SOURCE ,@QTY ,@CRAFTHOUR ,@CRAFTPAY ,@REALITYHOUR ,@REALITYPAY ,");
                        SqlStringBuilder.Append(" @PAYDIFFER ,@MOUTHASM ,@MOUTHPRODUCT ,@REQUEST3MOHTH，@SALEREQUESTCO ,@SALENETDEMAND ,@FIRSTSUMPRODUCT ,@MAXPRODUCTQTY ,@LASTPRODUCTPLAN ,");
                        SqlStringBuilder.Append(" @LASTPRODUCTHOUR ,@LASTPRODUCTLOAD ,@LASTPRODUCTVALUE ,@LASTPRODUCTPEOPLE ,@ISEXECT ,@REALTIMESTOKC ,@AGVOUTPRICE ,@SUMPEOPLEHOUR,@ENABLED,@SID");
                        SqlStringBuilder.Append("   ,'N','N','N')");

                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@PARTCODE", sapInfo.partcode);
                        dynamic.Add("@PDLINENAME", sapInfo.pdlinename);
                        dynamic.Add("@PDLINE", sapInfo.pdline);
                        dynamic.Add("@CATEGORY", sapInfo.category);
                        dynamic.Add("@SOURCE", sapInfo.source);
                        dynamic.Add("@QTY", sapInfo.qty);
                        dynamic.Add("@CRAFTHOUR", sapInfo.crafthour);
                        dynamic.Add("@CRAFTPAY", sapInfo.craftpay);
                        dynamic.Add("@REALITYHOUR", sapInfo.realityhour);
                        dynamic.Add("@REALITYPAY", sapInfo.realitypay);
                        dynamic.Add("@PAYDIFFER", sapInfo.paydiffer);
                        dynamic.Add("@MOUTHASM", sapInfo.mouthasm);
                        dynamic.Add("@MOUTHPRODUCT", sapInfo.mouthproduct);
                        dynamic.Add("@REQUEST3MOHTH", sapInfo.request3mohth);
                        dynamic.Add("@SALEREQUESTCO", sapInfo.salerequestco);
                        dynamic.Add("@SALENETDEMAND", sapInfo.salenetdemand);
                        dynamic.Add("@FIRSTSUMPRODUCT", sapInfo.firstsumproduct);
                        dynamic.Add("@MAXPRODUCTQTY", sapInfo.maxproductqty);
                        dynamic.Add("@LASTPRODUCTPLAN", sapInfo.lastproductplan);
                        dynamic.Add("@LASTPRODUCTHOUR", sapInfo.lastproducthour);
                        dynamic.Add("@LASTPRODUCTLOAD", sapInfo.lastproductload);
                        dynamic.Add("@LASTPRODUCTVALUE", sapInfo.lastproductvalue);
                        dynamic.Add("@LASTPRODUCTPEOPLE", sapInfo.lastproductpeople);
                        dynamic.Add("@ISEXECT", sapInfo.isexect);
                        dynamic.Add("@REALTIMESTOKC", sapInfo.realtimestokc);
                        dynamic.Add("@AGVOUTPRICE", sapInfo.agvoutprice);
                        dynamic.Add("@SUMPEOPLEHOUR", sapInfo.sumpeoplehour);
                        dynamic.Add("@ENABLED", sapInfo.ENABLED);
                        dynamic.Add("@SID", sid);
                        parameters.Add(dynamic);
                    }
                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.Message.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult SalesOrderDateMethod(string sid, List<SapSalessOrder> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);


                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        StringBuilder SqlStringBuilder = new StringBuilder(1024);
                        SapSalessOrder sapInfo = sapItemListParam[i];
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_SALES_ORDER ( ORDERCODE ,ITEMNO ,ORDERNAME ,PARTCODE , QTY ,INTENTIONDATE ,AGREEONDATE , PLANDATE ,RECDATE ,ENABLED ,SID ,SYNFLG,ACTFLG,STAFLG)");
                        SqlStringBuilder.Append("   VALUES  ( @ORDERCODE ,@ITEMNO ,@ORDERNAME ,@PARTCODE , @QTY ,@INTENTIONDATE ,@AGREEONDATE , @PLANDATE ,@RECDATE ,@ENABLED ,@SID");
                        SqlStringBuilder.Append("   ,'N','N','N')");

                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@ORDERCODE", sapInfo.OrderCode);
                        dynamic.Add("@ITEMNO", sapInfo.ItemNo);
                        dynamic.Add("@ORDERNAME", sapInfo.OrderName);
                        dynamic.Add("@PARTCODE", sapInfo.PartCode);
                        dynamic.Add("@QTY", sapInfo.Qty);
                        dynamic.Add("@INTENTIONDATE", sapInfo.IntentionDate);
                        dynamic.Add("@AGREEONDATE", sapInfo.AgreeOnDate);
                        dynamic.Add("@PLANDATE", sapInfo.PlanDate);
                        dynamic.Add("@RECDATE", sapInfo.RecDate);
                        dynamic.Add("@ENABLED", sapInfo.ENABLED);
                        dynamic.Add("@SID", sid);
                        parameters.Add(dynamic);
                    }
                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.Message.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult SalesReviewResultMethod(string sid, List<SapSalesReviewResult> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);


                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        StringBuilder SqlStringBuilder = new StringBuilder(1024);
                        SapSalesReviewResult sapInfo = sapItemListParam[i];
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_SALES_ReviewResult( ORDERCODE , PARTCODE ,QTY ,COST , PLANDATE ,ITENTIONDATE ,ENABLED ,SID ,SYNFLG,ACTFLG,STAFLG)");
                        SqlStringBuilder.Append("   VALUES  ( @ORDERCODE , @PARTCODE ,@QTY ,@COST , @PLANDATE ,@ITENTIONDATE ,@ENABLED ,@SID");
                        SqlStringBuilder.Append("   ,'N','N','N')");

                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@ORDERCODE", sapInfo.OrderCode);
                        dynamic.Add("@PARTCODE", sapInfo.PartCode);
                        dynamic.Add("@QTY", sapInfo.Qty);
                        dynamic.Add("@COST", sapInfo.Cost);
                        dynamic.Add("@PLANDATE", sapInfo.PlanDate);
                        dynamic.Add("@ITENTIONDATE", sapInfo.IntentionDate);
                        dynamic.Add("@ENABLED", sapInfo.ENABLED);
                        dynamic.Add("@SID", sid);
                        parameters.Add(dynamic);
                    }
                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.Message.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult PurachasesReqMethod(string sid, List<SapPurchasesReq> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);


                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        StringBuilder SqlStringBuilder = new StringBuilder(1024);
                        SapPurchasesReq sapInfo = sapItemListParam[i];
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_PURCHASES_REQ( ORDERCODE , PARTCODE ,QTY  , PLANDATE  ,ENABLED ,SID ,SYNFLG,ACTFLG,STAFLG)");
                        SqlStringBuilder.Append("   VALUES  ( @ORDERCODE , @PARTCODE ,@QTY , @PLANDATE ,@ENABLED ,@SID");
                        SqlStringBuilder.Append("   ,'N','N','N')");

                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@ORDERCODE", sapInfo.OrderCode);
                        dynamic.Add("@PARTCODE", sapInfo.PartCode);
                        dynamic.Add("@QTY", sapInfo.Qty);
                        dynamic.Add("@PLANDATE", sapInfo.PlanDate);
                        dynamic.Add("@ENABLED", sapInfo.ENABLED);
                        dynamic.Add("@SID", sid);
                        parameters.Add(dynamic);
                    }
                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.Message.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult SapSalesReviewNoticeMethod(string sid, List<SapSalesReviewNotice> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);


                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        StringBuilder SqlStringBuilder = new StringBuilder(1024);
                        SapSalesReviewNotice sapInfo = sapItemListParam[i];
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_SALES_ReviewNotice( ORDERCODE , FLAG, ENABLED ,SID ,SYNFLG,ACTFLG,STAFLG)");
                        SqlStringBuilder.Append("   VALUES  ( @ORDERCODE , @FLAG ,@ENABLED ,@SID");
                        SqlStringBuilder.Append("   ,'N','N','N')");

                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@ORDERCODE", sapInfo.OrderCode);
                        dynamic.Add("@FLAG", sapInfo.Flag);
                        dynamic.Add("@ENABLED", sapInfo.ENABLED);
                        dynamic.Add("@SID", sid);
                        parameters.Add(dynamic);
                    }
                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.Message.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult PurachasesMethod(string sid, List<SapPurchases> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);


                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        StringBuilder SqlStringBuilder = new StringBuilder(1024);
                        SapPurchases sapInfo = sapItemListParam[i];
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_PURCHASES_ORDER( ORDERCODE , PARTCODE ,QTY  , DELIVERYDATE  ,ENABLED ,SID ,SYNFLG,ACTFLG,STAFLG)");
                        SqlStringBuilder.Append("   VALUES  ( @ORDERCODE , @PARTCODE ,@QTY , @DELIVERYDATE ,@ENABLED ,@SID");
                        SqlStringBuilder.Append("   ,'N','N','N')");

                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@ORDERCODE", sapInfo.OrderCode);
                        dynamic.Add("@PARTCODE", sapInfo.PartCode);
                        dynamic.Add("@QTY", sapInfo.Qty);
                        dynamic.Add("@DELIVERYDATE", sapInfo.DeliveryDate);
                        dynamic.Add("@ENABLED", sapInfo.ENABLED);
                        dynamic.Add("@SID", sid);
                        parameters.Add(dynamic);
                    }
                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.Message.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult SalesAndDeliveryPlanExtendMethod(string sid, List<SapDnInterface_Extend> sapDns)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapDns));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapDns.Count; i++)
                    {
                        SapDnInterface_Extend sapDn = sapDns[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_DN(VBELN,POSNR,WERKS,LGORT,LFDAT,KUNNR,MATNR,KDMAT,LFIMG,MEINS,DELIVERTNOTICE,WLCOMPANY,ENABLED ");
                        SqlStringBuilder.Append("           ,SID,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@VBELN,@POSNR,@WERKS,@LGORT,@LFDAT,@KUNNR,@MATNR,@KDMAT,@LFIMG,@DELIVERTNOTICE,@WLCOMPANY,@ENABLED ");
                        SqlStringBuilder.Append("           ,@MEINS,'" + sid + "','N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@VBELN", sapDn.Vbeln);
                        dynamic.Add("@POSNR", sapDn.Posnr);
                        dynamic.Add("@WERKS", sapDn.Werks);
                        dynamic.Add("@LGORT", sapDn.Lgort);
                        dynamic.Add("@LFDAT", sapDn.Lfdat);
                        dynamic.Add("@KUNNR", sapDn.Kunnr);
                        dynamic.Add("@MATNR", sapDn.Matnr);
                        dynamic.Add("@KDMAT", sapDn.Kdmat);
                        dynamic.Add("@LFIMG", sapDn.Lfimg);
                        dynamic.Add("@MEINS", sapDn.Meins);
                        dynamic.Add("@DELIVERTNOTICE", sapDn.Delivertnotice);
                        dynamic.Add("@WLCOMPANY", sapDn.WLCompany);
                        dynamic.Add("@ENABLED", sapDn.enabled);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }
        /// <summary>
        /// 设备主数据接口
        /// </summary>
        /// <param name="sid"></param>
        /// <param name="sapItemListParam"></param>
        /// <returns></returns>

        public WmsInterfaceResult EquipmentDataMethod(string sid, List<SapEquipment> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        SapEquipment sapDn = sapItemListParam[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_EQU( EQUIPMENTNO ,EQUIPMENTNAME ,EQUIPMENTSTATUS ,EQUIPMENTSPECS ,ENABLED ");
                        SqlStringBuilder.Append("           ,SID,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@EQUIPMENTNO ,@EQUIPMENTNAME ,@EQUIPMENTSTATUS ,@EQUIPMENTSPECS,@ENABLED ");
                        SqlStringBuilder.Append("           ,'" + sid + "','N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@EQUIPMENTNO", sapDn.EquipmentNo);
                        dynamic.Add("@EQUIPMENTNAME", sapDn.EquipmentName);
                        dynamic.Add("@EQUIPMENTSTATUS", sapDn.EquipmentStaus);
                        dynamic.Add("@EQUIPMENTSPECS", sapDn.EquipmentSpecs);
                        dynamic.Add("@ENABLED", sapDn.ENABLED);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult EquipmentPdLineDataMethod(string sid, List<SapEquipmentPdLine> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        SapEquipmentPdLine sapDn = sapItemListParam[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_EQU_PDLINE ( PDLINECODE ,EQUIPMENTNO1 ,EQUIPMENTNO2 ,EQUIPMENTNO3 ,EQUIPMENTNO4 ,EQUIPMENTNO5 ,EQUIPMENTNO6 ,ENABLED  ");
                        SqlStringBuilder.Append("           ,SID,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@PDLINECODE ,@EQUIPMENTNO1 ,@EQUIPMENTNO2 ,@EQUIPMENTNO3 ,@EQUIPMENTNO4 ,@EQUIPMENTNO5 ,@EQUIPMENTNO6,@ENABLED ");
                        SqlStringBuilder.Append("           ,'" + sid + "','N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@PDLINECODE", sapDn.PdLineCode);
                        dynamic.Add("@EQUIPMENTNO1", sapDn.EquipmentNo1);
                        dynamic.Add("@EQUIPMENTNO2", sapDn.EquipmentNo2);
                        dynamic.Add("@EQUIPMENTNO3", sapDn.EquipmentNo3);
                        dynamic.Add("@EQUIPMENTNO4", sapDn.EquipmentNo4);
                        dynamic.Add("@EQUIPMENTNO5", sapDn.EquipmentNo5);
                        dynamic.Add("@EQUIPMENTNO6", sapDn.EquipmentNo6);
                        dynamic.Add("@ENABLED", sapDn.ENABLED);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult DepartmentDataMethod(string sid, List<SapDepartment> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        SapDepartment sapDn = sapItemListParam[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_DEP ( DEPTCODE ,DEPTNAME ,DEPTDESC ,ENABLED  ");
                        SqlStringBuilder.Append("           ,SID,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@DEPTCODE ,@DEPTNAME ,@DEPTDESC ,@ENABLED ");
                        SqlStringBuilder.Append("           ,'" + sid + "','N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@DEPTCODE", sapDn.Deptcode);
                        dynamic.Add("@DEPTNAME", sapDn.Deptname);
                        dynamic.Add("@DEPTDESC", sapDn.Deptdesc);
                        dynamic.Add("@ENABLED", sapDn.Enabled);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }

        public WmsInterfaceResult ERPUserDataMethod(string sid, List<SapUser> sapItemListParam)
        {
            using (IDbConnection dbConn = dapperDbContext.GetDbConnection())
            {
                dbConn.Open();
                WmsInterfaceResult interfaceResult = new WmsInterfaceResult();
                try
                {
                    StringBuilder IQSqlStringBuilder = new StringBuilder(1024);
                    IQSqlStringBuilder.Append("INSERT INTO dbo.IQ(SID,RECTIM,XMLCON ");
                    IQSqlStringBuilder.Append("           ,ACTFLG) ");
                    IQSqlStringBuilder.Append("     VALUES(@SID,@RECTIM,@XMLCON ");
                    IQSqlStringBuilder.Append("           ,@ACTFLG) ");

                    DynamicParameters IQdynamic = new DynamicParameters();
                    IQdynamic.Add("@SID", sid);
                    IQdynamic.Add("@RECTIM", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    IQdynamic.Add("@XMLCON", Newtonsoft.Json.JsonConvert.SerializeObject(sapItemListParam));
                    IQdynamic.Add("@ACTFLG", 'N');

                    dbConn.Execute(IQSqlStringBuilder.ToString(), IQdynamic);

                    StringBuilder SqlStringBuilder = new StringBuilder(1024);
                    List<string> sqlLists = new List<string>();
                    List<DynamicParameters> parameters = new List<DynamicParameters>();
                    for (int i = 0; i < sapItemListParam.Count; i++)
                    {
                        SapUser sapDn = sapItemListParam[i];
                        SqlStringBuilder = new StringBuilder(1024);
                        SqlStringBuilder.Append("INSERT INTO dbo.SAP_USER( SERIALNO ,NAME ,DEPARTMENT ,PDLINE ,ITEMCODE ,ENABLED  ");
                        SqlStringBuilder.Append("           ,SID,SYNFLG,ACTFLG,STAFLG) ");
                        SqlStringBuilder.Append("     VALUES(@SERIALNO ,@NAME ,@DEPARTMENT ,@PDLINE ,@ITEMCODE ,@ENABLED ");
                        SqlStringBuilder.Append("           ,'" + sid + "','N','N','N') ");
                        sqlLists.Add(SqlStringBuilder.ToString());

                        DynamicParameters dynamic = new DynamicParameters();
                        dynamic.Add("@SERIALNO", sapDn.SerialNo);
                        dynamic.Add("@NAME", sapDn.UserName);
                        dynamic.Add("@DEPARTMENT", sapDn.DepartCode);
                        dynamic.Add("@PDLINE", sapDn.PdLine);
                        dynamic.Add("@ITEMCODE", sapDn.ItemCode);
                        dynamic.Add("@ENABLED", sapDn.ENABLED);
                        parameters.Add(dynamic);
                    }

                    bool result = this.ExecuteTransaction(sqlLists, parameters);
                    if (result == true)
                    {
                        interfaceResult.success = true;
                        interfaceResult.message = "成功";
                    }
                    else
                    {
                        interfaceResult.success = false;
                        interfaceResult.message = "数据添加失败，请检查";
                    }
                }
                catch (Exception ex)
                {
                    interfaceResult.success = false;
                    interfaceResult.message = ex.ToString();
                }
                return interfaceResult;
            }
        }
    }
}
